import {getSiteConfig} from "@/api/system/elements";


const config = {
  state: {
    siteConfig: {
      siteName: "",
      siteUrl: "",
      cmsUrl: "",
      siteLogo: "",
      siteDesc: "",
      siteFavicon: "",
      defaultHeader: "",
      authorName: "",
      authorSignature: "",
      authorHeader: "",
      github: "",
      gitee: "",
      copyright: "",
      recordNumber: "",
      homeKeywords: "",
      homeDesc: ""
    },
  },
  mutations: {
    SET_SITE_CONFIG: (state, config) => {
      for (const prop in config) {
        state.siteConfig[prop] = config[prop]
      }
    }
  },
  actions: {
    // 获取网站配置
    GetSiteConfig({ commit }) {
      return new Promise(resolve => {
        // 向后端请求路由数据
        getSiteConfig().then(res => {
          if (res.code === 200) {
            commit('SET_SITE_CONFIG', res.data)
            resolve()
          }
        })
      })
    }
  }
}

export default config
